package com.train.user.controller;

import com.train.common.annotation.Anonymous;
import com.train.user.service.IUserWechatService;
import com.train.user.domain.UserWechat;
import com.train.user.dto.UserWechatDTO;
import com.train.common.core.controller.BaseController;
import com.train.common.core.domain.AjaxResult;
import com.train.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 微信用户关联Controller
 * 
 * @author train
 */
@RestController
@RequestMapping("/user/wechat")
public class UserWechatController extends BaseController {
    
    @Autowired
    private IUserWechatService userWechatService;

    /**
     * 查询微信用户关联列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(UserWechat userWechat) {
        startPage();
        List<UserWechat> list = userWechatService.selectUserWechatList(userWechat);
        return getDataTable(list);
    }

    /**
     * 获取微信用户关联详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(userWechatService.selectUserWechatById(id));
    }

    /**
     * 新增微信用户关联
     */
    @PostMapping
    public AjaxResult add(@RequestBody UserWechatDTO userWechatDTO) {
        return toAjax(userWechatService.insertUserWechat(userWechatDTO));
    }

    /**
     * 修改微信用户关联
     */
    @PutMapping
    public AjaxResult edit(@RequestBody UserWechatDTO userWechatDTO) {
        return toAjax(userWechatService.updateUserWechat(userWechatDTO));
    }

    /**
     * 删除微信用户关联
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(userWechatService.deleteUserWechatByIds(ids));
    }
}